<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>变电站管理</title>
<style type="text/css">
#stCheck {
	float: left;
	width: 100%;
}
#stDisplay {
	background-color: #9CF;
	float: left;
	width: 400px;
}
#stItem {
	float: left;
	width: 600px;
	background-color: #6CF;
}
.stInfo {
	padding: 0px;
	width: 100%;
	margin: 0px;
	font-size: 12px;
	line-height: 20px;
}
.modi { font-size: 10px; }
#stCheck ul {
	margin: 0px;
	padding: 0px;
	list-style-type: none;
	width: 500px;
	display: block;
	float: left;
}
#stCheck ul li {
	margin: 0px;
	padding: 0px;
	float: left;
	display: block;
}
</style>
<link href="/css/allstyle.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="header">
  <?php include("../common/header.php") ?>
</div>
<div id="wrap">
  <div id="top"><a href="/job/stations/st_list.php">全部变电站列表</a> | <a href="/job/stations/st_insert.php">新增变电站数据</a>
    <?php require("../common/pdata_mysql.php");?>
    <?php 
?>
    <div id="stCheck">
      <form>
        <label for="st">变电站名称及编号查询</label>
        <input type="text" name="st" />
        <input type="submit" />
      </form>
      <?php		
		if(isset($_GET['st']))
		{
			$st = $_GET['st'];
			$sql = "select stid,stcode,stname,stoldname from stations where stname like '%".$st."%' or stoldname like '%".$st."%' Or stcode like '%".$st."%' order by stcode";
			$conn = mysql_pconnect($hostname_pdata,$username_pdata,$password_pdata);
			mysql_select_db("pdata");
			$rs = mysql_query($sql,$conn) or die(mysql_error());
			$countnum = mysql_num_rows($rs);
			while($row = mysql_fetch_array($rs))
			{
				echo "<ul><a href='?stid=".$row['stid']."&st=".$st."#info'>";
				echo "<li>"."编号：".$row['stcode']." | </li>";
				echo "<li>运行名称：".$row['stname']." | </li>";
				echo "<li>曾用名称：".$row['stoldname']."</li>";
				echo "</a></ul>";
			}
			mysql_close($conn);
			echo  "<p>查询到的数量为:".$countnum."</p>";
		}
	else
		echo "没有查询到，请重新输入";
		
	?>
    </div>
  </div>
  <div id="stDisplay">
    <p><a name="info" id="info"></a>变电站站信息</p>
    <table border="1" class="stInfo">
      <tr>
        <td width='95px' align="center">项目名称</td>
        <td align="center">内容</td>
      </tr>
      <?php 
/////////////////////////////////
//按照stid的要求显示全部的变电站数据//
//或者只是部分的显示变电站的数据等等///
////////////////////////////////

$conn = mysql_pconnect($hostname_pdata,$username_pdata,$password_pdata);

if(isset($_GET['stid']))
	{$check = " WHERE stid = ".$_GET['stid'];
	
	//查询$pdata中的stations的列数
		mysql_select_db("information_schema");
		$sql = "SELECT count(*) FROM COLUMNS WHERE table_schema = 'pdata' and table_name='stations'";
		$rs = mysql_query($sql,$conn) or die(mysql_error());
		$row = mysql_fetch_array($rs);
		$maxi = $row[0];
		//echo $maxi;
		
		//查询全部或者满足要求$check要求的数据列表
		mysql_select_db("pdata");
		$sql = "SELECT * FROM stations".$check;
		$rs = mysql_query($sql,$conn) or die(mysql_error());
		
		while($row = mysql_fetch_array($rs))
		{
			//echo "<station>";
			for($i=0;$i<$maxi-2;$i++)
				{
					$proper = mysql_fetch_field($rs,$i);
					echo "<tr>";
					if($proper->name == 'stname')
					{
						echo "<td>".$proper->name."</td>";
						echo "<td>".$row[$i];
						//echo "<span class='modi'><a href='st.php?modi=修改&stid=".$row[0]."'>[修改]</a></span>";
						echo "</td>";
					}
					else
					{
						echo "<td>".$proper->name."</td>";
						echo "<td>".$row[$i]."</td>";
					}
					echo "</tr>";
			//echo "</station>";
				}
			echo "<tr>";
			echo "<td><a target='_new' href='st_edit.php?stid=".$row['stid']."'>编辑</a></td>";
			//echo "<td></td>";
			echo "</tr>";
		}

	}
else
	$check = "";
	
mysql_close($conn);
?>
    </table>
  </div>
  <div id="stItem">
    <p>工程及所属输变电工程信息</p>
    <ul>
      <?php 
  $conn = mysql_pconnect($hostname_pdata,$username_pdata,$password_pdata);
  mysql_select_db("pdata");
  if(isset($_GET['stid']))
	{$check = " WHERE stid = ".$_GET['stid'];
	$sql = "select * from itemdetail ".$check;
	$rs = mysql_query($sql,$conn) or die(mysql_error());
	while($row = mysql_fetch_array($rs))
	{
		echo "<li>".$row['iname']." | 阶段代码：".$row['phid']."</li>";
		
		echo "<ul>";
		$sqltemp = "select * from project where pid = ".$row['pid'];
		$rstemp = mysql_query($sqltemp,$conn);
		while($rowtemp = mysql_fetch_array($rstemp))
		{
			echo "<li>所属输变电工程：";
			echo $rowtemp['projectname'];
			if($rowtemp['oldname']!='无')
				echo "=".$rowtemp['oldname'];
			
			echo "</li>";
		}
		echo "</ul>";
	}		
	}
  ?>
    </ul>
  </div>
  <div id="bottom"></div>
  <div class="clean"></div>
</div>
<div id="footer">
  <?php include("../common/footer.php") ?>
</div>
</body>
</html>